package com.donlim.dev.dto;

import com.donlim.dev.enums.ResultCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by 星 on 2020/11/3
 * 通用返回结果
 */
@Getter
@Setter
public class CommonResult<T> {

    private Integer code;
    private T data;
    private String message;

    public CommonResult(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    /**
     * 成功返回结果
     * @param data
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(T data){
        return new CommonResult<>(ResultCode.SUCCESS.getCode(),data,ResultCode.SUCCESS.getMessage());
    }

    /**
     * 成功返回结果
     * @param data
     * @param message
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(T data,String message){
        return new CommonResult<>(ResultCode.SUCCESS.getCode(),data,message);
    }

    /**
     * 成功返回结果
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> success(){
        return new CommonResult<>(ResultCode.SUCCESS.getCode(),null,ResultCode.SUCCESS.getMessage());
    }

    /**
     * 失败返回结果
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(){
        return new CommonResult<>(ResultCode.FAILED.getCode(),null,ResultCode.FAILED.getMessage());
    }

    /**
     * 失败返回结果
     * @param message
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(String message){
        return new CommonResult<>(ResultCode.FAILED.getCode(),null,message);
    }

    /**
     * 失败返回结果
     * @param errorCode
     * @param message
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(Integer errorCode,String message){
        return new CommonResult<>(errorCode,null,message);
    }


}
